package br.ufrj.dcc.smarthotel.activities;

import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import br.ufrj.dcc.smarthotel.R;
import br.ufrj.dcc.smarthotel.controls.DashboardControl;
import br.ufrj.dcc.smarthotel.entities.Session;
import br.ufrj.dcc.smarthotel.listeners.DashboardMenuItemClickListener;

public class DashboardActivity extends AppActivity {
    private ImageView imgTour;
    private ImageView imgEvents;
    private ImageView imgServices;
    private TextView txtWelcome;
    private Button btnLogout;
    
    private Session sessionInfo;
    
    private DashboardMenuItemClickListener listener;
    private DashboardControl control;
    private String sessionLocation;
    
    /***
     * Metodo chamado na criacao da Activity
     * @param savedInstanceState - Parametros para a inicializacao da Activity
     */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        //Seta o Layout da Activity
        setContentView(R.layout.dashboard);
        
        this.findAllViews();
        this.control = new DashboardControl(this);
        this.sessionLocation = this.getIntent().getExtras().getString("sessionLocation");
        
        this.fetchSessionInfo();
        
        this.listener = new DashboardMenuItemClickListener(this);
        
        this.imgEvents.setOnClickListener(this.listener);
        this.imgServices.setOnClickListener(this.listener);
        this.imgTour.setOnClickListener(this.listener);
        this.btnLogout.setOnClickListener(this.listener);
    }
    
    private void fetchSessionInfo() {
    	this.control.getSessionInfo();
    }
    
    private void findAllViews() {
    	this.imgEvents = (ImageView)this.findViewById(R.id.dashboardIconEvents);
    	this.imgTour = (ImageView)this.findViewById(R.id.dashboardIconTour);
    	this.imgServices = (ImageView)this.findViewById(R.id.dashboardIconServices);
    	this.txtWelcome = (TextView)this.findViewById(R.id.txtWelcome);
    	this.btnLogout = (Button)this.findViewById(R.id.btnLogout);
    }

	public String getSessionLocation() {
		return sessionLocation;
	}

	public void setDashboardSessionInfo(Session sessionInfo) {
		AppActivity.setSessionInfo(sessionInfo);
		
		this.sessionInfo = sessionInfo;
		this.setUserName(this.sessionInfo.getUser().getName());
	}
	
	public void setUserName(String name) {
		String welcomeText = this.getString(R.string.lbl_Welcome, name);
		
		this.txtWelcome.setText(welcomeText);
	}
}
